package com.aaa.tars.util;

/**
 * 订单状态枚举（code改为String类型，适配数据库String字段）
 */
public enum OrderStateEnum {

    // 进行中
    WAIT_PAY("11", "待付款"),
    PAID_SUCCESS("12", "已付款"),
    TICKET_TAKEN("13", "已取票"),
    WAIT_REVIEW("14", "退款待审核"),
    WAIT_REFUND("15", "已退款"),

    // 结束状态
    CANCEL_WAIT_PAY("20", "待付款退单结束"),
    CANCEL_PAY_TIMEOUT("21", "付款超时结束"),
    CANCEL_AFTER_PAID("22", "退款已驳回"),
    REFUND_REJECTED("23", "退款审核不通过结束"),
    REFUND_SUCCESS("24", "退款完成结束"),
    TICKET_TIMEOUT("25", "取票超时结束"),
    TICKET_RETURNED("26", "退票结束"),
    COMMENT_TIMEOUT("27", "点评超时结束"),
    COMMENT_DONE("28", "点评完成结束");

    private final String code;  // 改为String类型
    private final String desc;

    OrderStateEnum(String code, String desc) {  // 构造方法参数改为String
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {  // 返回String类型code
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据String类型code获取枚举（适配实体类的String orderState）
     */
    public static OrderStateEnum fromCode(String code) {
        for (OrderStateEnum state : values()) {
            if (state.code.equals(code)) {  // 字符串相等判断
                return state;
            }
        }
        return null;
    }

    /**
     * 根据String类型code获取描述
     */
    public static String getDescByCode(String code) {
        OrderStateEnum state = fromCode(code);
        return state != null ? state.getDesc() : "未知状态";
    }
}